#include <iostream>
#include<iomanip>
#include <math.h>
using namespace std;
int main()
{
	cout << "请直接关闭窗口以结束程序" << endl;
	while (1)
	{
		//小数点位数控制
		int i =2;
		cout << "请输入精确到小数点后的位数" << endl;
		cin >> i;
		while (cin.fail())//检查输入的是整数
		{
			cout << "输入错误，请输入一个整数" << endl;
			cin.clear();
			while (cin.get() != '\n')
			{
				continue;
			}
			cin >> i;
		}

		cout << "请输入算术表达式，例如1+1" << endl;
		//限制输入的表达式
		char op;
		double x, y;
		cin >> x >> op >> y;//输入表达式
		while (cin.fail() || cin.fail() || cin.fail())//表达式输入有误时，进入循环纠正
		{
			cout << "请输入正确的表达式" << endl;
			cin.clear();
			while (cin.get() != '\n')
			{
				continue;
			}
			cin >> x >> op >> y;
		}

		switch (op)//运算
		{
			case '+': cout << "结果的值为：" << setprecision(i) << x + y << endl;
				break;
			case '-': cout << "结果的值为：" << setprecision(i) << x - y << endl;
				break;
			case '*': cout << "结果的值为" << setprecision(i) << x * y << endl;
				break;
			case '/': cout << "结果的值为:" << setprecision(i) << x / y << endl;
				break;
			default:cout << "你输入的表达式有错误" << endl;
		}

	}
	return 0;
}
